#include "channel.h"

void Channel::update()
{
	if(free)
		return;
	//If the channel isn't playing or it's paused then free it
	if(!Mix_Playing(id))
	{
		if(!Mix_Paused(id))
		{
			free=true;
			Mix_UnregisterAllEffects(id);
		}
	}
}

void Channel::playSound(Sound *s,Mix_Chunk *c)
{
	switch(s->getEffect())
	{
		case Sound::NO_EFFECT:
			break;
		case Sound::PANNING:
			Mix_SetPanning(id,-(s->getPanning()-128),s->getPanning()+128);
			break;
		case Sound::DISTANCE:
			Mix_SetDistance(id,s->getDistance());
			break;
		case Sound::POSITION:
			Mix_SetPosition(id,s->getDistance(),s->getPosition());
			break;
	}
	Mix_PlayChannel(id,c,0);
	free=false;
}
